﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="CuitWinTreeItem.cs" company="">
//   
// </copyright>
// <summary>
//   The cuit win tree item.
// </summary>
// --------------------------------------------------------------------------------------------------------------------
namespace UITest.CUIT.CuitControls.WinControls
{
    using System.Collections.Generic;

    using Microsoft.VisualStudio.TestTools.UITesting;
    using Microsoft.VisualStudio.TestTools.UITesting.WinControls;

    /// <summary>
    ///     The cuit win tree item.
    /// </summary>
    public class CuitWinTreeItem : CuitWinControl<WinTreeItem>
    {
        #region Constructors and Destructors

        /// <summary>
        ///     Initializes a new instance of the <see cref="CuitWinTreeItem" /> class.
        /// </summary>
        public CuitWinTreeItem()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinTreeItem"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        public CuitWinTreeItem(UITestControl testControl)
            : base(testControl)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinTreeItem"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        public CuitWinTreeItem(UITestControl testControl, string searchProperties)
            : base(testControl, searchProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinTreeItem"/> class.
        /// </summary>
        /// <param name="testControl">
        /// The test control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        /// <param name="filterProperties">
        /// The filter properties.
        /// </param>
        public CuitWinTreeItem(UITestControl testControl, string searchProperties, string filterProperties)
            : base(testControl, searchProperties, filterProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinTreeItem"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        public CuitWinTreeItem(ICuitControlBase wrappedControl, string searchProperties)
            : base(wrappedControl, searchProperties)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="CuitWinTreeItem"/> class.
        /// </summary>
        /// <param name="wrappedControl">
        /// The wrapped control.
        /// </param>
        /// <param name="searchProperties">
        /// The search properties.
        /// </param>
        /// <param name="filterProperties">
        /// The filter properties.
        /// </param>
        public CuitWinTreeItem(ICuitControlBase wrappedControl, string searchProperties, string filterProperties)
            : base(wrappedControl, searchProperties, filterProperties)
        {
        }

        #endregion

        #region Public Properties

        /// <summary>
        ///     Gets or sets a value indicating whether expanded.
        /// </summary>
        public bool Expanded
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Expanded;
            }

            set
            {
                this._control.WaitForControlReady();
                this._control.Expanded = value;
            }
        }

        /// <summary>
        ///     Gets a value indicating whether has child nodes.
        /// </summary>
        public bool HasChildNodes
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.HasChildNodes;
            }
        }

        /// <summary>
        ///     Gets the nodes.
        /// </summary>
        public UITestControlCollection Nodes
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.Nodes;
            }
        }

        /// <summary>
        ///     Gets the nodes as cui te.
        /// </summary>
        public List<CuitWinTreeItem> NodesAsCUITe
        {
            get
            {
                this._control.WaitForControlReady();
                var list = new List<CuitWinTreeItem>();
                foreach (WinTreeItem node in this._control.Nodes)
                {
                    var cuiteItem = new CuitWinTreeItem();
                    cuiteItem.WrapReady(node);
                    list.Add(cuiteItem);
                }

                return list;
            }
        }

        /// <summary>
        ///     Gets the parent node.
        /// </summary>
        public UITestControl ParentNode
        {
            get
            {
                this._control.WaitForControlReady();
                return this._control.ParentNode;
            }
        }

        #endregion

        #region Public Methods and Operators

        /// <summary>
        ///     Gets a value indicating whether selected.
        /// </summary>
        /// <returns>
        ///     The <see cref="bool" />.
        /// </returns>
        public bool IsSelected()
        {
            this._control.WaitForControlReady();
            return this._control.Selected;
        }

        /// <summary>
        ///     The select.
        /// </summary>
        public void Select()
        {
            this._control.WaitForControlReady();
            this.WriteTestOutput(string.Empty);
            this._control.Selected = true;
        }

        /// <summary>
        ///     The un select.
        /// </summary>
        public void UnSelect()
        {
            this._control.WaitForControlReady();
            this.WriteTestOutput(string.Empty);
            this._control.Selected = false;
        }

        #endregion
    }
}